package com.jyh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jyh.mapper.UserMapper;
import com.jyh.pojo.User;
import com.jyh.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Override
    public void sendMessage(String to, String context) {
        SimpleMailMessage message = new SimpleMailMessage();
        // 发件人，不能省略
        log.info("发件人:{}",from);
        //
        message.setFrom("验证码"+"<"+from+">");
        // 收件人，可以是多个，不能省略
        message.setTo(to);
        // 邮件标题，可以省略，省略之后展示的是：<无标题>
        message.setSubject("【showye外卖】登录验证码");
        // 邮件正文，一定不能少，不然会报错，不能省略
        message.setText(context);
        // 发送
        mailSender.send(message);
    }
}
